package com.spring.controller;


import com.spring.controller.utils.JwtUtil;
import com.spring.dao.Login;
import com.spring.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.io.IOException;
import java.util.List;

@Controller

public class LoginController {
    @Autowired
    private Login loginService;

    @PostMapping("/login")
    public String  login(User user, RedirectAttributes redirectAttributes) throws IOException {
        Boolean flag = loginService.Select(user.getLogin_name(), user.getPassword());
        System.out.println(user.getPassword()+user.getLogin_name());
        // 创建Token:token保存到user对象
        String token = JwtUtil.createToken();
        if (flag==true)
        {
            redirectAttributes.addAttribute("token", token);
            return "redirect:http://localhost:8081/Dishs.html";
        }else {
            return "redirect:/login.html";
        }

    }
//    @PostMapping("/a")
//    public List<User>  a(User user, RedirectAttributes redirectAttributes) throws IOException{
//        List<User> users=
//        return users;
//    }


}
